package cn.yuemouren.leetcode;

/**
 * @Author: Timi
 * @Description: 167. 两数之和 II - 输入有序数组
 * @Date: 2020/7/27 8:24
 */
public class Test_167 {

    public int[] twoSum(int[] numbers, int target) {
        int left = 0;
        int right = numbers.length - 1;
        while (left < right){
            int numberLeft = numbers[left];
            int numberRight = numbers[right];
            if(target - numberLeft < numberRight){
                right--;
            } else if(target - numberLeft > numberRight){
                left++;
            } else {
                break;
            }
        }
        int[] res = {left + 1,right + 1};
        return res;
    }

    public static void main(String[] args) {
        int[] arr = {2, 7, 11, 15};
        new Test_167().twoSum(arr,9);
    }
}
